home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / 5_in_row.swf / scripts / frame_11 / DoAction.as
Encoding:
Text File  |  2010-04-12  |  4.6 KB  |  222 lines

  1. function setBonus()
  2. {
  3.    if(rowLength == tilesToRow)
  4.    {
  5.       bonus += rowBonus;
  6.       rowsKilledBonus += rowBonus;
  7.    }
  8.    else
  9.    {
  10.       bonus += rowBonus * 2;
  11.       rowsKilledBonus += rowBonus * 3;
  12.    }
  13. }
  14. function levelCheck()
  15. {
  16.    level = Math.floor(score / 2500) + 1;
  17.    if(level != preLevel)
  18.    {
  19.       preLevel = level;
  20.       bonus += (tilesMax - getTilesOnBoard()) * 25;
  21.       score += bonus;
  22.       mcSounds.gotoAndPlay("levelBonus");
  23.       mcBonus.bonus = bonus;
  24.       mcBonus.play();
  25.    }
  26. }
  27. function startKillAnim(pNr)
  28. {
  29.    if(aBoard[pNr] != 0)
  30.    {
  31.       var newTile = mcTile.duplicateMovieClip("mcTile" + depth,depth++);
  32.       newTile.gotoAndStop(aBoard[pNr] + 1);
  33.       newTile._x = this["mcTile" + pNr]._x;
  34.       newTile._y = this["mcTile" + pNr]._y;
  35.       newTile.delay = rndNumber(1,10,0);
  36.       newTile.g = 1;
  37.       newTile.onEnterFrame = function()
  38.       {
  39.          if(--this.delay <= 0)
  40.          {
  41.             this.g *= 1.33;
  42.             this._y += this.g;
  43.             if(this._y > 480)
  44.             {
  45.                this.removeMovieClip();
  46.             }
  47.          }
  48.       };
  49.    }
  50. }
  51. function checkTile()
  52. {
  53.    tileNr = getBoardPos(posCounter);
  54.    fNr = aBoard[tileNr];
  55.    if(fNr == 0)
  56.    {
  57.       return sub1();
  58.    }
  59.    var link = getLink(tileNr,0);
  60.    if(link == 0)
  61.    {
  62.       subNeighbour("row");
  63.       return sub3();
  64.    }
  65.    return sub3();
  66. }
  67. function sub1()
  68. {
  69.    if(++posCounter == xMax)
  70.    {
  71.       posCounter = 0;
  72.       if(++row == yMax)
  73.       {
  74.          return false;
  75.       }
  76.       return sub2();
  77.    }
  78.    return sub2();
  79. }
  80. function sub2()
  81. {
  82.    lResult = checkTile();
  83.    if(lResult == false)
  84.    {
  85.       return false;
  86.    }
  87.    return fNr;
  88. }
  89. function sub3()
  90. {
  91.    var link = getLink(tileNr,1);
  92.    if(link == 0)
  93.    {
  94.       subNeighbour("col");
  95.       return sub1();
  96.    }
  97.    return sub1();
  98. }
  99. function subNeighbour(pLine)
  100. {
  101.    if(pLine == "row")
  102.    {
  103.       if(xMax - posCounter >= tilesToRow)
  104.       {
  105.          this["aTilesToKillRow" + row].push(tileNr);
  106.          var i = posCounter + 1;
  107.          while(i < xMax)
  108.          {
  109.             var tNr = getBoardPos(i);
  110.             var nNr = aBoard[tNr];
  111.             setLink(getBoardPos(i - 1),0,nNr);
  112.             if(nNr == 0 || nNr != fNr)
  113.             {
  114.                if(this["aTilesToKillRow" + row].length < tilesToRow)
  115.                {
  116.                   this["aTilesToKillRow" + row] = [];
  117.                }
  118.                return undefined;
  119.             }
  120.             this["aTilesToKillRow" + row].push(tNr);
  121.             i++;
  122.          }
  123.       }
  124.    }
  125.    else if(yMax - row >= tilesToRow)
  126.    {
  127.       var tempRow = row;
  128.       this["aTilesToKillCol" + posCounter].push(tileNr);
  129.       var i = tempRow + 1;
  130.       while(i < yMax)
  131.       {
  132.          row = i;
  133.          var tNr = getBoardPos(posCounter);
  134.          var nNr = aBoard[tNr];
  135.          row = i - 1;
  136.          setLink(getBoardPos(posCounter),1,nNr);
  137.          row = i;
  138.          if(nNr == 0 || nNr != fNr)
  139.          {
  140.             if(this["aTilesToKillCol" + posCounter].length < tilesToRow)
  141.             {
  142.                this["aTilesToKillCol" + posCounter] = [];
  143.             }
  144.             row = tempRow;
  145.             return undefined;
  146.          }
  147.          this["aTilesToKillCol" + posCounter].push(tNr);
  148.          i++;
  149.       }
  150.       row = tempRow;
  151.    }
  152. }
  153. bonus = 0;
  154. depth = 1000;
  155. score += time;
  156. clearLinks();
  157. initCheck();
  158. lResult = checkTile();
  159. var i = 0;
  160. while(i < yMax)
  161. {
  162.    rowLength = this["aTilesToKillRow" + i].length;
  163.    if(rowLength != 0)
  164.    {
  165.       playSound("killRow");
  166.       while(this["aTilesToKillRow" + i].length > 0)
  167.       {
  168.          tileNr = this["aTilesToKillRow" + i].shift();
  169.          startKillAnim(tileNr);
  170.          aBoard[tileNr] = 0;
  171.       }
  172.       setBonus();
  173.    }
  174.    i++;
  175. }
  176. var i = 0;
  177. while(i < xMax)
  178. {
  179.    rowLength = this["aTilesToKillCol" + i].length;
  180.    if(rowLength != 0)
  181.    {
  182.       playSound("killRow");
  183.       while(this["aTilesToKillCol" + i].length > 0)
  184.       {
  185.          tileNr = this["aTilesToKillCol" + i].shift();
  186.          startKillAnim(tileNr);
  187.          aBoard[tileNr] = 0;
  188.       }
  189.       setBonus();
  190.    }
  191.    i++;
  192. }
  193. if(getTilesOnBoard() == 0)
  194. {
  195.    bonus += 1000;
  196.    rowsKilledBonus += rowBonus * 2;
  197. }
  198. if(bonus != 0)
  199. {
  200.    score += bonus;
  201.    levelCheck();
  202.    mcBonus.bonus = bonus;
  203.    mcBonus.play();
  204. }
  205. else
  206. {
  207.    levelCheck();
  208. }
  209. if(rowsKilledBonus / rowBonusFactor >= 1 && tilesOnBoard >= criticalAmount)
  210. {
  211.    rowsKilledBonus -= rowBonusFactor;
  212.    initTimer();
  213.    time = int(time * 1.5);
  214.    gotoAndStop(12);
  215. }
  216. else
  217. {
  218.    makeNewTile();
  219.    initTimer();
  220.    gotoAndStop(8);
  221. }
  222.